// pages/health/health.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      oldinfo:"",
      loading:true,
      hinfo:"",
      recommend:``
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var id=options.id
    this.getInfo(id)
    this.getHealthInfo(id);
  
    },
    getHealthInfo(id){
          wx.cloud.callFunction({
            name:"health",
          data:{
              type:"selectById",
              id:id
          }
          }).then(res=>{
            console.log(res)
              this.setData({
                hinfo:res.result.data[0],
            
              })
              var glucose=this.data.hinfo.glucose
              console.log(glucose)
              if(Number(glucose)<=3.9){
                  this.getFood("0") 
                  console.log("---------")
              }else if(Number(glucose)>3.9&&Number(glucose)<=5.5){
                this.getFood("1") 
              }else if(Number(glucose)>5.6&&Number(glucose)<=6.9){
                this.getFood("1") 
              }else if(Number(glucose)>7.0&&Number(glucose)<=9.9){
                this.getFood("2") 
              }else if(Number(glucose)>10.0&&Number(glucose)<=13.9){
                this.getFood("3") 
              }else if(Number(glucose)>14){
                this.getFood("4") 
              }
          })
 },

 getFood(type){
  wx.cloud.callFunction({
    name:"food",
    data:{
      type:"selectByType",
      t:type
    }
  }).then(res=>{
    console.log(res)
    this.setData({
      recommend:res.result.data[0].text,
      loading:false
    })
  })
 },
  getInfo(id1){
    wx.cloud.callFunction({
      name:"Oldman",
      data:{
        type:"selectById",
        id:id1
      }
    }).then(res=>{
      console.log(res)
        this.setData({
          oldinfo:res.result.data

        })
    })
  }

  




})